<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *会员分组
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
);

//红包记录
if($_RQ['op']=='list'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_scrm_worker_redlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['usernum']=pdo_count('jy_scrm_member',array('groupid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			$item['qunnum']=0;
		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'workerid','title'=>'员工操作','type'=>'select','options'=>'workers','option_value'=>'name'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'types'),
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'status','title'=>'领取状态','type'=>'radio','options'=>'status'),
			array('name'=>'fee','title'=>'零钱金额','type'=>'string'),
			array('name'=>'ordersn','title'=>'商户订单号/微信付款单号','type'=>'string'),
			array('name'=>'remark','title'=>'员工备注','type'=>'string'),
			array('name'=>'msg','title'=>'给客户留言','type'=>'string'),
			array('name'=>'createtime','title'=>'发送时间','type'=>'time'),
		),'batch'=>array(
			array('type'=>'post','url'=>'jy_merchscrm/merch.worker.redlog/uplog/','title'=>'同步红包记录'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'分组名称','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'select','options'=>'status2'),
		)
	);
	$return['workers']=pdo_getall('jy_scrm_worker',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']),array('id','name'),'id');
	$return['status']=$this->red_status;
	$return['types']=$this->red_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_scrm_worker_redlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='uplog'){
	exi('同步红包成功！');
}